home *** CD-ROM | disk | FTP | other *** search
/ Best of Shareware / Best of PC Windows Shareware 1.0 - Wayzata Technology (7111) (1993).iso / mac / ZIPPED / DOS / GRAPHICS / RAYSH386.ZIP / SRC / LIGHT.C < prev    next >
C/C++ Source or Header  |  1991-07-18  |  2KB  |  88 lines

  1. /*
  2.  * light.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: light.c,v 4.0 91/07/17 14:35:01 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    light.c,v $
  19.  * Revision 4.0  91/07/17  14:35:01  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "light.h"
  24.  
  25. Light *
  26. LightCreate(light, meth, color)
  27. LightRef light;
  28. LightMethods *meth;
  29. Color *color;
  30. {
  31.     Light *ltmp;
  32.  
  33.     if (light == (LightRef)NULL || meth == (LightMethods *)NULL)
  34.         return (Light *)NULL;
  35.  
  36.     ltmp = (Light *)share_malloc(sizeof(Light));
  37.     ltmp->light = light;
  38.     ltmp->methods = meth;
  39.     ltmp->color = *color;
  40.     ltmp->next = (Light *)NULL;
  41.     ltmp->cache = (ShadowCache *)NULL;
  42.     ltmp->shadow = TRUE;
  43.     return ltmp;
  44. }
  45.  
  46. LightMethods *
  47. LightMethodsCreate()
  48. {
  49.     return (LightMethods *)share_calloc(1, sizeof(LightMethods));
  50. }
  51.  
  52. /*
  53.  * Compute light color.  Returns FALSE if in full shadow, TRUE otherwise.
  54.  * Computed light color is stored in 'color'.
  55.  */
  56. int
  57. LightIntens(lp, ray, dist, noshadow, color)
  58. Light *lp;
  59. Ray *ray;
  60. Float dist;
  61. int noshadow;
  62. Color *color;
  63. {
  64.     if (lp->methods->intens)
  65.         return (*lp->methods->intens)(lp->light, &lp->color,
  66.             lp->cache, ray, dist, noshadow || !lp->shadow, color);
  67.     RLerror(RL_ABORT, "Cannot compute light intensity!\n");
  68.     return FALSE;
  69. }
  70.  
  71. /*
  72.  * Calculate ray and distance from position to light.
  73.  */
  74. int
  75. LightDirection(lp, objpos, lray, dist)
  76. Light *lp;
  77. Vector *objpos, *lray;
  78. Float *dist;
  79. {
  80.     if (lp->methods->dir) {
  81.         (*lp->methods->dir)(lp->light, objpos, lray, dist);
  82.         return TRUE;
  83.     } else {
  84.         RLerror(RL_ABORT, "Cannot compute light direction!\n");
  85.         return FALSE;
  86.     }
  87. }
  88.